package common.model.converter;

import common.model.po.SysAuthority;
import common.model.vo.ButtonVo;
import common.model.vo.MenuVo;

import java.util.Objects;

/**
 * 描述
 *
 * @author 米泽鹏
 * @since 2023-10-31 下午 5:12
 */
public class CommonSysAuthorityConverter {

	public static MenuVo poToMenuVo(SysAuthority po) {
		if (po == null) {
			return null;
		}
		MenuVo menuVO = new MenuVo();
		menuVO.setPath(po.getPath());
		menuVO.setName(po.getName());
		menuVO.setComponent(po.getComponent());
		menuVO.setRedirect(po.getRedirect());
		menuVO.getMeta().setSort(po.getSort());
		MenuVo.Meta meta = menuVO.getMeta();
		meta.setId(po.getId());
		meta.setParentId(po.getParentId());
		meta.setType(po.getType());
		meta.setTitle(po.getTitle());
		meta.setIcon(po.getIcon());
		meta.setHidden(Objects.equals(po.getHidden(), 1));
		meta.setAffix(Objects.equals(po.getAffix(), 1));
		meta.setKeepAlive(Objects.equals(po.getKeepAlive(), 1));
		return menuVO;
	}

	public static ButtonVo poToButtonVO(SysAuthority sysAuthority) {
		if (sysAuthority == null) {
			return null;
		}
		ButtonVo buttonVO = new ButtonVo();
		buttonVO.setName(sysAuthority.getName());
		buttonVO.setResources(sysAuthority.getResources());
		return buttonVO;
	}

}
